SOURCES=$(wildcard src/*.cpp)
OBJECTS := $(addprefix obj/,$(notdir $(SOURCES:.cpp=.o)))
TOOLSRC:=$(wildcard tools/*.cpp)
TOOLS:=$(TOOLSRC:.cpp=.out)
TOOLS_OBJECTS=obj/rpi.o obj/i2cdevice.o

COMPILE_FLAGS := -O -Wall
LD_FLAGS := -lbcm2835 -lboost_thread
EXECUTABLE=fenpi

all: $(SOURCES) $(OBJECTS) tools/main.out tools/batmon.out tools/pwm.out tools/ultra.out tools/acc.out $(EXECUTABLE)


$(EXECUTABLE): $(OBJECTS) 
	cp tools/main.out ./fenpi
obj/%.o: src/%.cpp
	g++ $(COMPILE_FLAGS) -c -o $@ $<
tools/batmon.out: tools/batmon.cpp $(TOOLS_OBJECTS) obj/batterymonitor.o
	g++ $(COMPILE_FLAGS) -o $@ $^ -Isrc $(LD_FLAGS) 
tools/pwm.out: tools/pwm.cpp $(TOOLS_OBJECTS) obj/motorcontroller.o  obj/batterymonitor.o
	g++ $(COMPILE_FLAGS) -o $@ $^ -Isrc $(LD_FLAGS) 
tools/ultra.out: tools/ultra.cpp $(TOOLS_OBJECTS) obj/ultrasound.o obj/utils.o
	g++ $(COMPILE_FLAGS) -o $@ $^ -Isrc $(LD_FLAGS) 
tools/main.out: tools/main.cpp $(TOOLS_OBJECTS) obj/imu.o obj/mathtools.o obj/LSM303A.o obj/LSM303M.o obj/L3G4200D.o obj/motorcontroller.o obj/imuprocessor.o
	g++ $(COMPILE_FLAGS) -o $@ $^ -Isrc $(LD_FLAGS) 
tools/acc.out: tools/acc.cpp $(TOOLS_OBJECTS) obj/mathtools.o obj/LSM303A.o obj/LSM303M.o obj/L3G4200D.o obj/imu.o obj/imuprocessor.o
	g++ $(COMPILE_FLAGS) -o $@ $^ -Isrc $(LD_FLAGS) 
clean:
	rm -f fenpi
	rm -f obj/*.o
	rm -f tools/*.out
#tools/*.out: I
